<!DOCTYPE html><html lang="zh-CN" data-theme="dark"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"><title>SonarQube代码扫描 | J.のblog</title><meta name="keywords" content="jenkins,SonarQube"><meta name="author" content="J."><meta name="copyright" content="J."><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#0d0d0d"><meta name="description" content="一、代码质量测试 1. 代码测试工具 SonarQube：   官方网站：https:&#x2F;&#x2F;www.sonarqube.org&#x2F;  SonarQube 是一个用于代码质量管理的开放平台，通过插件机制,SonarQube 可以集成不同的测试工具，代码分析工具，以及持续集成工具。与持续集成工具（例如 Hudson&#x2F;Jenkins等）不同，SonarQube并不是简单的把不同的代码检查工具结果（">
<meta property="og:type" content="article">
<meta property="og:title" content="SonarQube代码扫描">
<meta property="og:url" content="http://dycloudnavite.love/2019/09/23/SonarQube%E4%BB%A3%E7%A0%81%E6%89%AB%E6%8F%8F/index.html">
<meta property="og:site_name" content="J.のblog">
<meta property="og:description" content="一、代码质量测试 1. 代码测试工具 SonarQube：   官方网站：https:&#x2F;&#x2F;www.sonarqube.org&#x2F;  SonarQube 是一个用于代码质量管理的开放平台，通过插件机制,SonarQube 可以集成不同的测试工具，代码分析工具，以及持续集成工具。与持续集成工具（例如 Hudson&#x2F;Jenkins等）不同，SonarQube并不是简单的把不同的代码检查工具结果（">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="http://dycloudnavite.love/img/sonarqube.png">
<meta property="article:published_time" content="2019-09-23T10:34:23.000Z">
<meta property="article:modified_time" content="2022-08-17T03:03:01.358Z">
<meta property="article:author" content="J.">
<meta property="article:tag" content="jenkins">
<meta property="article:tag" content="SonarQube">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="http://dycloudnavite.love/img/sonarqube.png"><link rel="shortcut icon" href="/dujie5416/img/touxiang.png"><link rel="canonical" href="http://dycloudnavite.love/2019/09/23/SonarQube%E4%BB%A3%E7%A0%81%E6%89%AB%E6%8F%8F/"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/dujie5416/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.min.css" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = { 
  root: '/dujie5416/',
  algolia: {"appId":"9GWB2VV7GN","apiKey":"dac56ec5b0b1f45281251ee59db4d637","indexName":"blog","hits":{"per_page":6},"languages":{"input_placeholder":"搜索文章","hits_empty":"找不到您查询的内容：${query}","hits_stats":"找到 ${hits} 条结果，用时 ${time} 毫秒"}},
  localSearch: undefined,
  translate: {"defaultEncoding":2,"translateDelay":0,"msgToTraditionalChinese":"繁","msgToSimplifiedChinese":"簡"},
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":false},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '天',
  date_suffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: undefined,
  lightbox: 'fancybox',
  Snackbar: undefined,
  source: {
    justifiedGallery: {
      js: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.js',
      css: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.css'
    }
  },
  isPhotoFigcaption: false,
  islazyload: false,
  isAnchor: false
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: 'SonarQube代码扫描',
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2022-08-17 11:03:01'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          if (t === 'dark') activateDarkMode()
          else if (t === 'light') activateLightMode()
        
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
    const detectApple = () => {
      if(/iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
        document.documentElement.classList.add('apple')
      }
    }
    detectApple()
    })(window)</script><link rel="stylesheet" href="/xxx.css"><link rel="stylesheet" href="/css/universe.css"><link rel="stylesheet" href="/css/custom.css"><style type="text/css">#toggle-sidebar {bottom: 80px}</style><link rel="stylesheet" href="https://fastly.jsdelivr.net/gh/tzy13755126023/BLOG_SOURCE/css/function.min.css"><link rel="stylesheet" href="/css/rightMenu.css"><style type="text/css">#toggle-sidebar {left:100px}</style><!-- hexo injector head_end start --><link rel="stylesheet" href="https://cdn.cbd.int/hexo-butterfly-clock-anzhiyu/lib/clock.min.css" /><!-- hexo injector head_end end --><meta name="generator" content="Hexo 6.2.0"><link rel="alternate" href="/dujie5416/atom.xml" title="J.のblog" type="application/atom+xml">
</head><body><div id="loading-box"><div class="loading-left-bg"></div><div class="loading-right-bg"></div><div class="spinner-box"><div class="configure-border-1"><div class="configure-core"></div></div><div class="configure-border-2"><div class="configure-core"></div></div><div class="loading-word">加载中...</div></div></div><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src="/dujie5416/img/touxiang.png" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="sidebar-site-data site-data is-center"><a href="/dujie5416/archives/"><div class="headline">文章</div><div class="length-num">73</div></a><a href="/dujie5416/tags/"><div class="headline">标签</div><div class="length-num">17</div></a><a href="/dujie5416/categories/"><div class="headline">分类</div><div class="length-num">11</div></a></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/dujie5416/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/dujie5416/archives/"><i class="fa-fw fas fa-archive"></i><span> 归档</span></a></div><div class="menus_item"><a class="site-page" href="/dujie5416/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/dujie5416/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div></div></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header" style="background-image: url('/dujie5416/img/longzhu.png')"><nav id="nav"><span id="blog_name"><a id="site-name" href="/dujie5416/">J.のblog</a></span><div id="menus"><div id="search-button"><a class="site-page social-icon search"><i class="fas fa-search fa-fw"></i><span> 搜索</span></a></div><div class="menus_items"><div class="menus_item"><a class="site-page" href="/dujie5416/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/dujie5416/archives/"><i class="fa-fw fas fa-archive"></i><span> 归档</span></a></div><div class="menus_item"><a class="site-page" href="/dujie5416/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/dujie5416/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div></div><div id="toggle-menu"><a class="site-page"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">SonarQube代码扫描</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2019-09-23T10:34:23.000Z" title="发表于 2019-09-23 18:34:23">2019-09-23</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2022-08-17T03:03:01.358Z" title="更新于 2022-08-17 11:03:01">2022-08-17</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/dujie5416/categories/SonarQube/">SonarQube</a></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" id="" data-flag-title="SonarQube代码扫描"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="busuanzi_value_page_pv"><i class="fa-solid fa-spinner fa-spin"></i></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><h1 id="一、代码质量测试"><a href="#一、代码质量测试" class="headerlink" title="一、代码质量测试"></a>一、代码质量测试</h1><p> <strong>1. 代码测试工具 SonarQube：</strong></p>
<blockquote>
<p> 官方网站：<a target="_blank" rel="noopener" href="https://www.sonarqube.org/">https://www.sonarqube.org/</a></p>
</blockquote>
<p>SonarQube 是一个用于代码质量管理的开放平台，通过插件机制,SonarQube 可以集成不同的测试工具，代码分析工具，以及持续集成工具。与持续集成工具（例如 Hudson&#x2F;Jenkins等）不同，SonarQube并不是简单的把不同的代码检查工具结果（例如FindBugs，PMD等）直接显示在web页面上，而是通过不同的插件针对这些结果进行再加工处理，通过量化的方式度量代码质量的变化，从而可以方便的对不同规模和种类的工程进行代码质量管理。在对其他工具的支持方面，Sonar不仅提供了对IDE的支持，可以在Eclipse和Interlij IDEA 这些工具里联机查看结果，同时Sonar还对大量的持续集成工具提供了接口支持，可以很方便的在持续集成中使用SnoarQube的插件还可以对java以外的其他编程语言提供支持，对国际化以及报告文档化也有良好的支持。<br> <strong>2. 安装sonarqube</strong><br>在jenkins-master中安装sonarqube</p>
<pre class="line-numbers language-powershell" data-language="powershell"><code class="language-powershell"><span class="token namespace">[root@jenkins src]</span><span class="token comment"># ll</span>
<span class="token operator">-</span>rw-r-<span class="token operator">-</span>r-<span class="token operator">-</span> 1 root root 143286376 Aug 22 16:56 sonarqube-6<span class="token punctuation">.</span>5<span class="token punctuation">.</span>zip
<span class="token namespace">[root@jenkins src]</span><span class="token comment"># unzip sonarqube-6.5.zip </span>
Archive:  sonarqube-6<span class="token punctuation">.</span>5<span class="token punctuation">.</span>zip
   creating: sonarqube-6<span class="token punctuation">.</span>5/
   creating: sonarqube-6<span class="token punctuation">.</span>5/bin/
   creating: sonarqube-6<span class="token punctuation">.</span>5/bin/windows-x86-32/
  inflating: sonarqube-6<span class="token punctuation">.</span>5/bin/windows-x86-32/wrapper<span class="token punctuation">.</span>exe  
   creating: sonarqube-6<span class="token punctuation">.</span>5/bin/windows-x86-32/lib/
  inflating: sonarqube-6<span class="token punctuation">.</span>5/bin/windows-x86-32/lib/wrapper<span class="token punctuation">.</span>dll  
   creating: sonarqube-6<span class="token punctuation">.</span>5/bin/macosx-universal-64/
<span class="token namespace">[root@jenkins src]</span><span class="token comment"># ln -s /app/src/sonarqube-6.5 /app/sonarqube</span>
<span class="token namespace">[root@jenkins src]</span><span class="token comment"># ll /app/</span>
  tal 0
▽rwxrwxrwx 1 root root  21 Aug 21 17:49 jdk <span class="token operator">-</span>> <span class="token operator">/</span>app/src/jdk1<span class="token punctuation">.</span>8<span class="token punctuation">.</span>0_60/
lrwxrwxrwx 1 root root  22 Aug 22 17:02 sonarqube <span class="token operator">-</span>> <span class="token operator">/</span>app/src/sonarqube-6<span class="token punctuation">.</span>5
drwxr-xr-x 4 root root 170 Aug 22 17:01 src<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>
<p>修改sonarqube配置文件</p>
<pre class="line-numbers language-powershell" data-language="powershell"><code class="language-powershell"><span class="token namespace">[root@jenkins conf]</span><span class="token comment"># vim /app/sonarqube/conf/sonar.properties</span>
sonar<span class="token punctuation">.</span>jdbc<span class="token punctuation">.</span>username=sonar   <span class="token comment">#配置数据库用户名</span>
sonar<span class="token punctuation">.</span>jdbc<span class="token punctuation">.</span>password=123456  <span class="token comment">#配置数据库密码</span>
sonar<span class="token punctuation">.</span>web<span class="token punctuation">.</span>port=9000
sonar<span class="token punctuation">.</span>web<span class="token punctuation">.</span>host=0<span class="token punctuation">.</span>0<span class="token punctuation">.</span>0<span class="token punctuation">.</span>0<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span></span></code></pre>

<p> <strong>3. 安装数据库（注意：只支持5.6以上）</strong></p>
<pre class="line-numbers language-powershell" data-language="powershell"><code class="language-powershell"><span class="token comment">#将数据库导入linux，执行mysql安装脚本（如果没有mysql用户必须先创建mysql用户）</span>
<span class="token namespace">[root@jenkins-slave tools]</span><span class="token comment"># ll</span>
total 498272
<span class="token operator">-</span>rw-r-<span class="token operator">-</span>r-<span class="token operator">-</span> 1 root root       256 Aug 22 17:11 my<span class="token punctuation">.</span>cnf
<span class="token operator">-</span>rw-r-<span class="token operator">-</span>r-<span class="token operator">-</span> 1 root root 328979165 Aug 22 17:05 mysql-5<span class="token punctuation">.</span>6<span class="token punctuation">.</span>42-linux-glibc2<span class="token punctuation">.</span>12-x86_64<span class="token punctuation">.</span>tar<span class="token punctuation">.</span>gz
<span class="token operator">-</span>rw-r-<span class="token operator">-</span>r-<span class="token operator">-</span> 1 root root      1470 Aug 22 17:11 mysql-install<span class="token punctuation">.</span>sh
<span class="token namespace">[root@jenkins-slave tools]</span><span class="token comment"># sh mysql-install.sh </span>
Loaded plugins: fastestmirror
Loading mirror speeds <span class="token keyword">from</span> cached hostfile
 <span class="token operator">*</span> base: mirrors<span class="token punctuation">.</span>aliyun<span class="token punctuation">.</span>com
 <span class="token operator">*</span> extras: mirrors<span class="token punctuation">.</span>aliyun<span class="token punctuation">.</span>com
 <span class="token operator">*</span> updates: mirrors<span class="token punctuation">.</span>aliyun<span class="token punctuation">.</span>com
Package gcc-4<span class="token punctuation">.</span>8<span class="token punctuation">.</span>5-36<span class="token punctuation">.</span>el7_6<span class="token punctuation">.</span>2<span class="token punctuation">.</span>x86_64 already installed and latest version
Package gcc-c+<span class="token operator">+</span><span class="token operator">-</span>4<span class="token punctuation">.</span>8<span class="token punctuation">.</span>5-36<span class="token punctuation">.</span>el7_6<span class="token punctuation">.</span>2<span class="token punctuation">.</span>x86_64 already installed and latest version
Package wget-1<span class="token punctuation">.</span>14-18<span class="token punctuation">.</span>el7_6<span class="token punctuation">.</span>1<span class="token punctuation">.</span>x86_64 already installed and latest version
Package autoconf-2<span class="token punctuation">.</span>69-11<span class="token punctuation">.</span>el7<span class="token punctuation">.</span>noarch already installed and latest version
Package net-tools-2<span class="token punctuation">.</span>0-0<span class="token punctuation">.</span>24<span class="token punctuation">.</span>20131004git<span class="token punctuation">.</span>el7<span class="token punctuation">.</span>x86_64 already installed and latest version
Package lrzsz-0<span class="token punctuation">.</span>12<span class="token punctuation">.</span>20-36<span class="token punctuation">.</span>el7<span class="token punctuation">.</span>x86_64 already installed and latest version
Package iotop-0<span class="token punctuation">.</span>6-4<span class="token punctuation">.</span>el7<span class="token punctuation">.</span>noarch already installed and latest version
Package lsof-4<span class="token punctuation">.</span>87-6<span class="token punctuation">.</span>el7<span class="token punctuation">.</span>x86_64 already installed and latest version
Package iotop-0<span class="token punctuation">.</span>6-4<span class="token punctuation">.</span>el7<span class="token punctuation">.</span>noarch already installed and latest version
Package 1:bash-completion-2<span class="token punctuation">.</span>1-6<span class="token punctuation">.</span>el7<span class="token punctuation">.</span>noarch already installed and latest version
Resolving Dependencies
<span class="token operator">--</span>> Running transaction check
<span class="token operator">--</span><span class="token operator">-</span>> Package vim-enhanced<span class="token punctuation">.</span>x86_64 2:7<span class="token punctuation">.</span>4<span class="token punctuation">.</span>160-5<span class="token punctuation">.</span>el7 will be updated
<span class="token operator">--</span><span class="token operator">-</span>> Package vim-enhanced<span class="token punctuation">.</span>x86_64 2:7<span class="token punctuation">.</span>4<span class="token punctuation">.</span>160-6<span class="token punctuation">.</span>el7_6 will be an update
<span class="token operator">--</span>> Processing Dependency: vim-common = 2:7<span class="token punctuation">.</span>4<span class="token punctuation">.</span>160-6<span class="token punctuation">.</span>el7_6 <span class="token keyword">for</span> package: 2:vim-enhanced-7<span class="token punctuation">.</span>4<span class="token punctuation">.</span>160-6<span class="token punctuation">.</span>el7_6<span class="token punctuation">.</span>x86_64
<span class="token operator">--</span>> Running transaction check
<span class="token operator">--</span><span class="token operator">-</span>> Package vim-common<span class="token punctuation">.</span>x86_64 2:7<span class="token punctuation">.</span>4<span class="token punctuation">.</span>160-5<span class="token punctuation">.</span>el7 will be updated
<span class="token operator">--</span><span class="token operator">-</span>> Package vim-common<span class="token punctuation">.</span>x86_64 2:7<span class="token punctuation">.</span>4<span class="token punctuation">.</span>160-6<span class="token punctuation">.</span>el7_6 will be an update
<span class="token operator">--</span>> Finished Dependency Resolution

Dependencies Resolved

===================================================================================================================================
 Package                         Arch                      Version                                Repository                  Size
===================================================================================================================================
Updating:
 vim-enhanced                    x86_64                    2:7<span class="token punctuation">.</span>4<span class="token punctuation">.</span>160-6<span class="token punctuation">.</span>el7_6                      updates                    1<span class="token punctuation">.</span>0 M
Updating <span class="token keyword">for</span> dependencies:
 vim-common                      x86_64                    2:7<span class="token punctuation">.</span>4<span class="token punctuation">.</span>160-6<span class="token punctuation">.</span>el7_6                      updates                    5<span class="token punctuation">.</span>9 M

WARNING: Default config file <span class="token operator">/</span>etc/my<span class="token punctuation">.</span>cnf exists on the system
This file will be read by default by the MySQL server
<span class="token keyword">If</span> you <span class="token keyword">do</span> not want to use this<span class="token punctuation">,</span> either remove it<span class="token punctuation">,</span> or use the
<span class="token operator">--</span>defaults-file argument to mysqld_safe when starting the server

‘<span class="token operator">/</span>usr/bin/mysql’ <span class="token operator">-</span>> ‘<span class="token operator">/</span>usr/local/mysql/bin/mysql’
‘<span class="token operator">/</span><span class="token keyword">var</span><span class="token operator">/</span>lib/mysql/mysql<span class="token punctuation">.</span>sock’ <span class="token operator">-</span>> ‘<span class="token operator">/</span><span class="token keyword">data</span><span class="token operator">/</span>mysql/mysql<span class="token punctuation">.</span>sock’
Starting MySQL<span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span> SUCCESS! <span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>
<p>创建数据库</p>
<pre class="line-numbers language-powershell" data-language="powershell"><code class="language-powershell"><span class="token namespace">[root@jenkins-slave tools]</span><span class="token comment"># mysql</span>
Welcome to the MySQL monitor<span class="token punctuation">.</span>  Commands <span class="token keyword">end</span> with <span class="token punctuation">;</span> or \g<span class="token punctuation">.</span>
Your MySQL connection id is 2
Server version: 5<span class="token punctuation">.</span>6<span class="token punctuation">.</span>42 MySQL Community Server <span class="token punctuation">(</span>GPL<span class="token punctuation">)</span>

Copyright <span class="token punctuation">(</span>c<span class="token punctuation">)</span> 2000<span class="token punctuation">,</span> 2018<span class="token punctuation">,</span> Oracle and/or its affiliates<span class="token punctuation">.</span> All rights reserved<span class="token punctuation">.</span>

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates<span class="token punctuation">.</span> Other names may be trademarks of their respective
owners<span class="token punctuation">.</span>

<span class="token function">Type</span> <span class="token string">'help;'</span> or <span class="token string">'\h'</span> <span class="token keyword">for</span> help<span class="token punctuation">.</span> <span class="token function">Type</span> <span class="token string">'\c'</span> to clear the current input statement<span class="token punctuation">.</span>

mysql> 
mysql> CREATE DATABASE sonar CHARACTER <span class="token function">SET</span> utf8 COLLATE utf8_general_ci<span class="token punctuation">;</span>
Query OK<span class="token punctuation">,</span> 1 row affected <span class="token punctuation">(</span>0<span class="token punctuation">.</span>01 sec<span class="token punctuation">)</span>
<span class="token comment">#创建并授权用户</span>
mysql> grant all on sonar<span class="token punctuation">.</span><span class="token operator">*</span> to sonar@<span class="token string">"10.0.0.%"</span> identified by <span class="token string">"123456"</span><span class="token punctuation">;</span>
Query OK<span class="token punctuation">,</span> 0 rows affected <span class="token punctuation">(</span>0<span class="token punctuation">.</span>01 sec<span class="token punctuation">)</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>
<p>授权完之后再jenkins-master中查看mysql是否能够登陆到10.0.0.177</p>
<pre class="line-numbers language-powershell" data-language="powershell"><code class="language-powershell"><span class="token namespace">[root@jenkins conf]</span><span class="token comment"># mysql -usonar -p123456 -h 10.0.0.177</span>
Welcome to the MariaDB monitor<span class="token punctuation">.</span>  Commands <span class="token keyword">end</span> with <span class="token punctuation">;</span> or \g<span class="token punctuation">.</span>
Your MySQL connection id is 3
Server version: 5<span class="token punctuation">.</span>6<span class="token punctuation">.</span>42 MySQL Community Server <span class="token punctuation">(</span>GPL<span class="token punctuation">)</span>

Copyright <span class="token punctuation">(</span>c<span class="token punctuation">)</span> 2000<span class="token punctuation">,</span> 2018<span class="token punctuation">,</span> Oracle<span class="token punctuation">,</span> MariaDB Corporation Ab and others<span class="token punctuation">.</span>

<span class="token function">Type</span> <span class="token string">'help;'</span> or <span class="token string">'\h'</span> <span class="token keyword">for</span> help<span class="token punctuation">.</span> <span class="token function">Type</span> <span class="token string">'\c'</span> to clear the current input statement<span class="token punctuation">.</span>

MySQL <span class="token punctuation">[</span><span class="token punctuation">(</span>none<span class="token punctuation">)</span><span class="token punctuation">]</span>> 
MySQL <span class="token punctuation">[</span><span class="token punctuation">(</span>none<span class="token punctuation">)</span><span class="token punctuation">]</span>> <span class="token keyword">exit</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>

<p> <strong>4. 启动sonarQube</strong></p>
<pre class="line-numbers language-powershell" data-language="powershell"><code class="language-powershell"><span class="token namespace">[root@jenkins linux-x86-64]</span><span class="token comment"># /app/sonarqube/bin/linux-x86-64/sonar.sh  --help </span>
Usage: <span class="token operator">/</span>app/sonarqube/bin/linux-x86-64/sonar<span class="token punctuation">.</span>sh <span class="token punctuation">&#123;</span> console <span class="token punctuation">|</span> <span class="token function">start</span> <span class="token punctuation">|</span> stop <span class="token punctuation">|</span> restart <span class="token punctuation">|</span> status <span class="token punctuation">|</span> dump <span class="token punctuation">&#125;</span>
<span class="token namespace">[root@jenkins linux-x86-64]</span><span class="token comment"># /app/sonarqube/bin/linux-x86-64/sonar.sh  start</span>
Starting SonarQube<span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span>
Started SonarQube<span class="token punctuation">.</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span></span></code></pre>
<p>启动成功后可以登陆界面 10.0.0.175:9000 （master）<br><img src="https://img-blog.csdnimg.cn/16fd4b0340e74d16b72478417ff12612.png" alt="在这里插入图片描述"><br>用户名和密码都是admin——admin<br><img src="https://img-blog.csdnimg.cn/8db8237b312d4bf7b80e1eeb777f67a8.png" alt="请添加图片描述"><br>sonarQube也是基于插件的，所以需要安装插件<br><img src="https://img-blog.csdnimg.cn/a3cbf58ef9764434955b5b5a500817f2.png" alt="请添加图片描述"><br>汉化包不兼容6.x版本<br><img src="https://img-blog.csdnimg.cn/f82f077d212648c194adbdd200d85863.png" alt="请添加图片描述"><br>导入汉化包到 &#x2F;app&#x2F;sonarqube&#x2F;extensions&#x2F;plugins&#x2F;</p>
<pre class="line-numbers language-powershell" data-language="powershell"><code class="language-powershell"><span class="token namespace">[root@jenkins sonarqube]</span><span class="token comment"># cd extensions/plugins/</span>
<span class="token namespace">[root@jenkins plugins]</span><span class="token comment"># </span>
<span class="token comment">#这里面都是java插件包</span>
<span class="token namespace">[root@jenkins plugins]</span><span class="token comment"># ll</span>
total 44832
<span class="token operator">-</span>rw-r-<span class="token operator">-</span>r-<span class="token operator">-</span> 1 root root      129 Aug  1  2017 README<span class="token punctuation">.</span>txt
<span class="token operator">-</span>rw-r-<span class="token operator">-</span>r-<span class="token operator">-</span> 1 root root 11069007 Jul 31  2017 sonar-csharp-plugin-5<span class="token punctuation">.</span>10<span class="token punctuation">.</span>1<span class="token punctuation">.</span>1411<span class="token punctuation">.</span>jar
<span class="token operator">-</span>rw-r-<span class="token operator">-</span>r-<span class="token operator">-</span> 1 root root  1618672 Jul 31  2017 sonar-flex-plugin-2<span class="token punctuation">.</span>3<span class="token punctuation">.</span>jar
<span class="token operator">-</span>rw-r-<span class="token operator">-</span>r-<span class="token operator">-</span> 1 root root  4900103 Aug  1  2017 sonar-java-plugin-4<span class="token punctuation">.</span>12<span class="token punctuation">.</span>0<span class="token punctuation">.</span>11033<span class="token punctuation">.</span>jar
<span class="token operator">-</span>rw-r-<span class="token operator">-</span>r-<span class="token operator">-</span> 1 root root  3261889 Aug  1  2017 sonar-javascript-plugin-3<span class="token punctuation">.</span>1<span class="token punctuation">.</span>1<span class="token punctuation">.</span>5128<span class="token punctuation">.</span>jar
<span class="token operator">-</span>rw-r-<span class="token operator">-</span>r-<span class="token operator">-</span> 1 root root  3733262 Jul 31  2017 sonar-php-plugin-2<span class="token punctuation">.</span>10<span class="token punctuation">.</span>0<span class="token punctuation">.</span>2087<span class="token punctuation">.</span>jar
<span class="token operator">-</span>rw-r-<span class="token operator">-</span>r-<span class="token operator">-</span> 1 root root  4024311 Aug  1  2017 sonar-python-plugin-1<span class="token punctuation">.</span>8<span class="token punctuation">.</span>0<span class="token punctuation">.</span>1496<span class="token punctuation">.</span>jar
<span class="token operator">-</span>rw-r-<span class="token operator">-</span>r-<span class="token operator">-</span> 1 root root  3233128 Jul 31  2017 sonar-scm-git-plugin-1<span class="token punctuation">.</span>2<span class="token punctuation">.</span>jar
<span class="token operator">-</span>rw-r-<span class="token operator">-</span>r-<span class="token operator">-</span> 1 root root  6676141 Aug  1  2017 sonar-scm-svn-plugin-1<span class="token punctuation">.</span>5<span class="token punctuation">.</span>0<span class="token punctuation">.</span>715<span class="token punctuation">.</span>jar
<span class="token operator">-</span>rw-r-<span class="token operator">-</span>r-<span class="token operator">-</span> 1 root root  7368250 Aug  1  2017 sonar-xml-plugin-1<span class="token punctuation">.</span>4<span class="token punctuation">.</span>3<span class="token punctuation">.</span>1027<span class="token punctuation">.</span>jar
<span class="token namespace">[root@jenkins plugins]</span><span class="token comment"># rz</span>
rz waiting to receive<span class="token punctuation">.</span>
Starting zmodem transfer<span class="token punctuation">.</span>  Press Ctrl+C to cancel<span class="token punctuation">.</span>
Transferring sonar-l10n-zh-plugin-1<span class="token punctuation">.</span>11<span class="token punctuation">.</span>jar<span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span>
  100%      35 KB      35 KB/sec    00:00:01       0 Errors  
<span class="token comment">#上传进去之后重启sonarqube</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>
<p>重新进入网址已经是中文的了<br><img src="https://img-blog.csdnimg.cn/89956b77318241f583b1ee34cfcf8601.png" alt="请添加图片描述"></p>
<h1 id="二、部署扫描器-sonar-scanner"><a href="#二、部署扫描器-sonar-scanner" class="headerlink" title="二、部署扫描器 sonar-scanner"></a>二、部署扫描器 sonar-scanner</h1><ol>
<li>部署sonar-scanner<br>sonarqube通过调用扫描器sonar-scanner 进行代码质量分析，即扫描器的具体工作就是扫描代码。<br>然后sonar-scanner 扫描完成后会把扫描结果也写入到数据库中，所以sonarqube是基于数据库读出结果，所以就可以查到扫描结果了</li>
</ol>
<blockquote>
<p>下载地址：<a target="_blank" rel="noopener" href="https://docs.sonarqube.org/latest/analysis/scan/sonarscanner/">https://docs.sonarqube.org/latest/analysis/scan/sonarscanner/</a></p>
</blockquote>
<pre class="line-numbers language-powershell" data-language="powershell"><code class="language-powershell"><span class="token namespace">[root@jenkins src]</span><span class="token comment"># unzip sonar-scanner-2.6.1.zip </span>
Archive:  sonar-scanner-2<span class="token punctuation">.</span>6<span class="token punctuation">.</span>1<span class="token punctuation">.</span>zip
   creating: sonar-scanner-2<span class="token punctuation">.</span>6<span class="token punctuation">.</span>1/bin/
  inflating: sonar-scanner-2<span class="token punctuation">.</span>6<span class="token punctuation">.</span>1/bin/sonar-scanner  
  inflating: sonar-scanner-2<span class="token punctuation">.</span>6<span class="token punctuation">.</span>1/bin/sonar-runner  
   creating: sonar-scanner-2<span class="token punctuation">.</span>6<span class="token punctuation">.</span>1/conf/
  inflating: sonar-scanner-2<span class="token punctuation">.</span>6<span class="token punctuation">.</span>1/conf/sonar-scanner<span class="token punctuation">.</span>properties  
   creating: sonar-scanner-2<span class="token punctuation">.</span>6<span class="token punctuation">.</span>1/lib/
  inflating: sonar-scanner-2<span class="token punctuation">.</span>6<span class="token punctuation">.</span>1/lib/sonar-scanner-<span class="token function">cli</span><span class="token operator">-</span>2<span class="token punctuation">.</span>6<span class="token punctuation">.</span>1<span class="token punctuation">.</span>jar  
  inflating: sonar-scanner-2<span class="token punctuation">.</span>6<span class="token punctuation">.</span>1/bin/sonar-runner<span class="token punctuation">.</span>bat  
  inflating: sonar-scanner-2<span class="token punctuation">.</span>6<span class="token punctuation">.</span>1/bin/sonar-scanner<span class="token punctuation">.</span>bat  <span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>
<p>修改配置文件(连接数据库的)</p>
<pre class="line-numbers language-powershell" data-language="powershell"><code class="language-powershell"><span class="token namespace">[root@jenkins bin]</span><span class="token comment"># vim /app/sonar-scanner/conf/sonar-scanner.properties </span>
<span class="token comment">#Configure here general information about the environment, such as SonarQube DB details for example</span>
<span class="token comment">#No information about specific project should appear here</span>

<span class="token comment">#----- Default SonarQube server</span>
sonar<span class="token punctuation">.</span>host<span class="token punctuation">.</span>url=http:<span class="token operator">/</span><span class="token operator">/</span>localhost:9000

<span class="token comment">#----- Default source code encoding</span>
sonar<span class="token punctuation">.</span>sourceEncoding=UTF-8

<span class="token comment">#----- Global database settings (not used for SonarQube 5.2+)</span>
sonar<span class="token punctuation">.</span>jdbc<span class="token punctuation">.</span>username=sonar
sonar<span class="token punctuation">.</span>jdbc<span class="token punctuation">.</span>password=123456

<span class="token comment">#----- PostgreSQL</span>
<span class="token comment">#sonar.jdbc.url=jdbc:postgresql://localhost/sonar</span>

<span class="token comment">#----- MySQL</span>
sonar<span class="token punctuation">.</span>jdbc<span class="token punctuation">.</span>url=jdbc:mysql:<span class="token operator">/</span><span class="token operator">/</span>10<span class="token punctuation">.</span>0<span class="token punctuation">.</span>0<span class="token punctuation">.</span>177:3306/sonar?useUnicode=true&amp;amp<span class="token punctuation">;</span>characterEncoding=utf8

<span class="token comment">#----- Oracle</span>
<span class="token comment">#sonar.jdbc.url=jdbc:oracle:thin:@localhost/XE</span>

<span class="token comment">#----- Microsoft SQLServer</span>
<span class="token comment">#sonar.jdbc.url=jdbc:jtds:sqlserver://localhost/sonar;SelectMethod=Cursor</span>
~                                                                          <span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>
<p>sonar-scanner 是不需要启动的，他是被调用的，需要在扫描的目录执行这个命令,代码在哪里路径就在哪执行</p>
<pre class="line-numbers language-powershell" data-language="powershell"><code class="language-powershell"><span class="token namespace">[root@jenkins bin]</span><span class="token comment"># /app/sonar-scanner/bin/sonar-scanner </span><span aria-hidden="true" class="line-numbers-rows"><span></span></span></code></pre>
<p>然后上传各种语言的代码进行测试</p>
<pre class="line-numbers language-powershell" data-language="powershell"><code class="language-powershell"><span class="token comment">#里面存放着各种语言的代码</span>
<span class="token namespace">[root@jenkins python-sonar-runner]</span><span class="token comment"># ll /app/src/sonar-examples-master</span>
total 4
drwxr-xr-x 7 root root 130 Jul 25  2016 plugins
drwxr-xr-x 5 root root  85 Jul 25  2016 projects
<span class="token operator">-</span>rw-r-<span class="token operator">-</span>r-<span class="token operator">-</span> 1 root root 493 Jul 25  2016 README<span class="token punctuation">.</span>md<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>
<p>可以进入到目录中进行查看，可以看到各种语言的代码，我们进入到python中对python代码进行质量测试</p>
<pre class="line-numbers language-powershell" data-language="powershell"><code class="language-powershell"><span class="token namespace">[root@jenkins languages]</span><span class="token comment"># cd /app/src/sonar-examples-master/projects/languages/</span>
<span class="token namespace">[root@jenkins languages]</span><span class="token comment"># ls</span>
abap     cobol   css     generic-coverage  javascript      php    python                    swift  web
android  <span class="token function">cpp</span>     erlang  groovy            multi-language  pli    rpg                       vb6    xml
c        csharp  flex    java              objc            plsql  sonar-project<span class="token punctuation">.</span>properties  vbnet<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span></span></code></pre>
<p>然后进入到python-sonar-runner中进行代码测试</p>
<pre class="line-numbers language-powershell" data-language="powershell"><code class="language-powershell"><span class="token namespace">[root@jenkins sonar-scanner]</span><span class="token comment"># cd /app/src/sonar-examples-master/projects/languages/python/python-sonar-runner</span>
<span class="token namespace">[root@jenkins python-sonar-runner]</span><span class="token comment"># ls</span>
README<span class="token punctuation">.</span>md  sonar-project<span class="token punctuation">.</span>properties  src  validation<span class="token punctuation">.</span>txt
<span class="token namespace">[root@jenkins python-sonar-runner]</span><span class="token comment"># /app/sonar-scanner/bin/sonar-scanner </span>
INFO: Scanner configuration file: <span class="token operator">/</span>app/sonar-scanner/conf/sonar-scanner<span class="token punctuation">.</span>properties
INFO: Project root configuration file: <span class="token operator">/</span>app/src/sonar-examples-master/projects/languages/python/python-sonar-runner/sonar-project<span class="token punctuation">.</span>properties
INFO: SonarQube Scanner 2<span class="token punctuation">.</span>6<span class="token punctuation">.</span>1
INFO: Java 1<span class="token punctuation">.</span>8<span class="token punctuation">.</span>0_121 Oracle Corporation <span class="token punctuation">(</span>64-bit<span class="token punctuation">)</span>
INFO: Linux 3<span class="token punctuation">.</span>10<span class="token punctuation">.</span>0-957<span class="token punctuation">.</span>12<span class="token punctuation">.</span>2<span class="token punctuation">.</span>el7<span class="token punctuation">.</span>x86_64 amd64
INFO: User cache: <span class="token operator">/</span>root/<span class="token punctuation">.</span>sonar/cache
INFO: Load global settings
INFO: Load global settings <span class="token punctuation">(</span>done<span class="token punctuation">)</span> <span class="token punctuation">|</span> time=261ms
WARN: Property <span class="token string">'sonar.jdbc.url'</span> is not supported any more<span class="token punctuation">.</span> It will be ignored<span class="token punctuation">.</span> There is no longer any DB connection to the SQ database<span class="token punctuation">.</span>
WARN: Property <span class="token string">'sonar.jdbc.username'</span> is not supported any more<span class="token punctuation">.</span> It will be ignored<span class="token punctuation">.</span> There is no longer any DB connection to the SQ database<span class="token punctuation">.</span>
WARN: Property <span class="token string">'sonar.jdbc.password'</span> is not supported any more<span class="token punctuation">.</span> It will be ignored<span class="token punctuation">.</span> There is no longer any DB connection to the SQ database<span class="token punctuation">.</span>
INFO: User cache: <span class="token operator">/</span>root/<span class="token punctuation">.</span>sonar/cache
INFO: Load plugins index
INFO: Load plugins index <span class="token punctuation">(</span>done<span class="token punctuation">)</span> <span class="token punctuation">|</span> time=116ms
INFO: Plugin <span class="token namespace">[l10nzh]</span> defines <span class="token string">'l10nen'</span> as base plugin<span class="token punctuation">.</span> This metadata can be removed <span class="token keyword">from</span> manifest of l10n plugins since version 5<span class="token punctuation">.</span>2<span class="token punctuation">.</span>
INFO: SonarQube server 6<span class="token punctuation">.</span>5<span class="token punctuation">.</span>0
INFO: Default locale: <span class="token string">"en_US"</span><span class="token punctuation">,</span> source code encoding: <span class="token string">"UTF-8"</span>
INFO: <span class="token keyword">Process</span> project properties
INFO: Load project repositories
INFO: Load project repositories <span class="token punctuation">(</span>done<span class="token punctuation">)</span> <span class="token punctuation">|</span> time=122ms
INFO: Load quality profiles
INFO: Load quality profiles <span class="token punctuation">(</span>done<span class="token punctuation">)</span> <span class="token punctuation">|</span> time=246ms
INFO: Load active rules
INFO: Load active rules <span class="token punctuation">(</span>done<span class="token punctuation">)</span> <span class="token punctuation">|</span> time=1754ms
INFO: Load metrics repository
INFO: Load metrics repository <span class="token punctuation">(</span>done<span class="token punctuation">)</span> <span class="token punctuation">|</span> time=254ms
WARN: SCM provider autodetection failed<span class="token punctuation">.</span> No SCM provider claims to support this project<span class="token punctuation">.</span> Please use sonar<span class="token punctuation">.</span>scm<span class="token punctuation">.</span>provider to <span class="token keyword">define</span> SCM of your project<span class="token punctuation">.</span>
INFO: Publish mode
INFO: Project key: org<span class="token punctuation">.</span>sonarqube:python-simple-sonar-scanner
INFO: <span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">-</span>  Scan Python :: Simple Project : SonarQube Scanner
INFO: Load server rules
INFO: Load server rules <span class="token punctuation">(</span>done<span class="token punctuation">)</span> <span class="token punctuation">|</span> time=331ms
INFO: Language is forced to py
INFO: Base <span class="token function">dir</span>: <span class="token operator">/</span>app/src/sonar-examples-master/projects/languages/python/python-sonar-runner
INFO: Working <span class="token function">dir</span>: <span class="token operator">/</span>app/src/sonar-examples-master/projects/languages/python/python-sonar-runner/<span class="token punctuation">.</span>sonar
INFO: Source paths: src
INFO: Source encoding: UTF-8<span class="token punctuation">,</span> default locale: en_US
INFO: Index files
INFO: 9 files indexed
INFO: Quality profile <span class="token keyword">for</span> py: Sonar way
INFO: Sensor PythonXUnitSensor <span class="token namespace">[python]</span>
INFO: Sensor PythonXUnitSensor <span class="token namespace">[python]</span> <span class="token punctuation">(</span>done<span class="token punctuation">)</span> <span class="token punctuation">|</span> time=11ms
INFO: Sensor Python Squid Sensor <span class="token namespace">[python]</span>
INFO: Python unit test coverage
INFO: Python integration test coverage
INFO: Python overall test coverage
INFO: Sensor Python Squid Sensor <span class="token namespace">[python]</span> <span class="token punctuation">(</span>done<span class="token punctuation">)</span> <span class="token punctuation">|</span> time=614ms
INFO: Sensor SonarJavaXmlFileSensor <span class="token namespace">[java]</span>
INFO: Sensor SonarJavaXmlFileSensor <span class="token namespace">[java]</span> <span class="token punctuation">(</span>done<span class="token punctuation">)</span> <span class="token punctuation">|</span> time=0ms
INFO: Sensor Analyzer <span class="token keyword">for</span> <span class="token string">"php.ini"</span> files <span class="token namespace">[php]</span>
INFO: Sensor Analyzer <span class="token keyword">for</span> <span class="token string">"php.ini"</span> files <span class="token namespace">[php]</span> <span class="token punctuation">(</span>done<span class="token punctuation">)</span> <span class="token punctuation">|</span> time=10ms
INFO: Sensor Zero Coverage Sensor
INFO: Sensor Zero Coverage Sensor <span class="token punctuation">(</span>done<span class="token punctuation">)</span> <span class="token punctuation">|</span> time=35ms
INFO: Sensor CPD Block Indexer
INFO: Sensor CPD Block Indexer <span class="token punctuation">(</span>done<span class="token punctuation">)</span> <span class="token punctuation">|</span> time=61ms
INFO: No SCM system was detected<span class="token punctuation">.</span> You can use the <span class="token string">'sonar.scm.provider'</span> property to explicitly specify it<span class="token punctuation">.</span>
INFO: 5 files had no CPD blocks
INFO: Calculating CPD <span class="token keyword">for</span> 4 files
INFO: CPD calculation finished
INFO: Analysis report generated in 112ms<span class="token punctuation">,</span> <span class="token function">dir</span> size=54 KB
INFO: Analysis reports compressed in 27ms<span class="token punctuation">,</span> zip size=27 KB
INFO: Analysis report uploaded in 1424ms
INFO: ANALYSIS SUCCESSFUL<span class="token punctuation">,</span> you can browse http:<span class="token operator">/</span><span class="token operator">/</span>localhost:9000/dashboard/index/org<span class="token punctuation">.</span>sonarqube:python-simple-sonar-scanner
INFO: Note that you will be able to access the updated dashboard once the server has processed the submitted analysis report
INFO: More about the report processing at http:<span class="token operator">/</span><span class="token operator">/</span>localhost:9000/api/ce/task?id=AWy72tmj-QGXbgTpuyz-
INFO: Task total time: 9<span class="token punctuation">.</span>425 s
INFO: <span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span>
INFO: EXECUTION SUCCESS
INFO: <span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span>
INFO: Total time: 12<span class="token punctuation">.</span>871s
INFO: Final Memory: 43M/107M
INFO: <span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span>
<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>
<p>然后到sonar-qube网站中查看已经多了一个代码扫描结果<br><img src="https://img-blog.csdnimg.cn/33c8e10be911414f8fa2389647a95cac.png" alt="请添加图片描述"><br>进入到里面可以看到报错代码的具体行数<br><img src="https://img-blog.csdnimg.cn/cf8f4a2d9e2b4cd8b4b6060bc46cea4d.png" alt="请添加图片描述"><br>我们可以自己写段代码进行测试</p>
<pre class="line-numbers language-powershell" data-language="powershell"><code class="language-powershell"><span class="token namespace">[root@jenkins python-test]</span><span class="token comment"># mkdir src</span>
<span class="token comment">#手动创建一个python代码目录</span>
<span class="token namespace">[root@jenkins python-test]</span><span class="token comment"># pwd</span>
<span class="token operator">/</span>app/src/sonar-examples-master/projects/languages/python/python-test
<span class="token comment">#将python中别的配置文件cp一份</span>
<span class="token namespace">[root@jenkins python-test]</span><span class="token comment"># cp ../python-sonar-runner/sonar-project.properties .</span>
<span class="token namespace">[root@jenkins python-test]</span><span class="token comment"># ll</span>
total 4
<span class="token operator">-</span>rw-r-<span class="token operator">-</span>r-<span class="token operator">-</span> 1 root root 338 Aug 23 15:02 sonar-project<span class="token punctuation">.</span>properties
drwxr-xr-x 2 root root   6 Aug 23 15:01 src
<span class="token comment">#将src目录改名</span>
<span class="token namespace">[root@jenkins python-test]</span><span class="token comment"># mv src source</span>
<span class="token comment">#修改配置文件</span>
<span class="token namespace">[root@jenkins python-test]</span><span class="token comment"># vim sonar-project.properties </span>
<span class="token comment"># Required metadata</span>
sonar<span class="token punctuation">.</span>projectKey=python-test
sonar<span class="token punctuation">.</span>projectName=python-test
sonar<span class="token punctuation">.</span>projectVersion=1<span class="token punctuation">.</span>0
  
▽ Comma-separated paths to directories with sources <span class="token punctuation">(</span>required<span class="token punctuation">)</span>
sonar<span class="token punctuation">.</span>sources=source

<span class="token comment"># Language</span>
sonar<span class="token punctuation">.</span>language=py

<span class="token comment"># Encoding of the source files</span>
sonar<span class="token punctuation">.</span>sourceEncoding=UTF-8<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>
<p>进入代码目录中写一段正确的python代码</p>
<pre class="line-numbers language-powershell" data-language="powershell"><code class="language-powershell"><span class="token namespace">[root@jenkins python-test]</span><span class="token comment"># cd source/</span>
<span class="token namespace">[root@jenkins source]</span><span class="token comment"># vim test.py</span>
<span class="token comment">#/usr/bin/env python</span>
print <span class="token string">"hello world"</span>
<span class="token comment">#然后可以测试，可以看到代码是正确的</span>
<span class="token namespace">[root@jenkins source]</span><span class="token comment"># python test.py </span>
hello world<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>

<p>然后修改一下python代码让代码出错然后进行测试,可以看到执行代码已经报错</p>
<pre class="line-numbers language-powershell" data-language="powershell"><code class="language-powershell"><span class="token namespace">[root@jenkins source]</span><span class="token comment"># vim test.py    </span>
<span class="token comment">#/usr/bin/env python</span>
print <span class="token string">"hello world"</span>
print hello
<span class="token namespace">[root@jenkins source]</span><span class="token comment"># python test.py </span>
hello world
Traceback <span class="token punctuation">(</span>most recent call last<span class="token punctuation">)</span>:
  File <span class="token string">"test.py"</span><span class="token punctuation">,</span> line 3<span class="token punctuation">,</span> in &lt;module>
    print hello
NameError: name <span class="token string">'hello'</span> is not defined<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>
<p>然后执行扫描的命令</p>
<pre class="line-numbers language-powershell" data-language="powershell"><code class="language-powershell"><span class="token namespace">[root@jenkins python-test]</span><span class="token comment"># /app/sonar-scanner/bin/sonar-scanner </span>
INFO: Scanner configuration file: <span class="token operator">/</span>app/sonar-scanner/conf/sonar-scanner<span class="token punctuation">.</span>properties
INFO: Project root configuration file: <span class="token operator">/</span>app/src/sonar-examples-master/projects/languages/python/python-test/sonar-project<span class="token punctuation">.</span>properties
INFO: SonarQube Scanner 2<span class="token punctuation">.</span>6<span class="token punctuation">.</span>1
INFO: Java 1<span class="token punctuation">.</span>8<span class="token punctuation">.</span>0_121 Oracle Corporation <span class="token punctuation">(</span>64-bit<span class="token punctuation">)</span>
INFO: Linux 3<span class="token punctuation">.</span>10<span class="token punctuation">.</span>0-957<span class="token punctuation">.</span>12<span class="token punctuation">.</span>2<span class="token punctuation">.</span>el7<span class="token punctuation">.</span>x86_64 amd64
INFO: User cache: <span class="token operator">/</span>root/<span class="token punctuation">.</span>sonar/cache
INFO: Load global settings
INFO: Load global settings <span class="token punctuation">(</span>done<span class="token punctuation">)</span> <span class="token punctuation">|</span> time=534ms
WARN: Property <span class="token string">'sonar.jdbc.url'</span> is not supported any more<span class="token punctuation">.</span> It will be ignored<span class="token punctuation">.</span> There is no longer any DB connection to the SQ database<span class="token punctuation">.</span>
WARN: Property <span class="token string">'sonar.jdbc.username'</span> is not supported any more<span class="token punctuation">.</span> It will be ignored<span class="token punctuation">.</span> There is no longer any DB connection to the SQ database<span class="token punctuation">.</span>
WARN: Property <span class="token string">'sonar.jdbc.password'</span> is not supported any more<span class="token punctuation">.</span> It will be ignored<span class="token punctuation">.</span> There is no longer any DB connection to the SQ database<span class="token punctuation">.</span>
INFO: User cache: <span class="token operator">/</span>root/<span class="token punctuation">.</span>sonar/cache
INFO: Load plugins index
INFO: Load plugins index <span class="token punctuation">(</span>done<span class="token punctuation">)</span> <span class="token punctuation">|</span> time=202ms
INFO: Plugin <span class="token namespace">[l10nzh]</span> defines <span class="token string">'l10nen'</span> as base plugin<span class="token punctuation">.</span> This metadata can be removed <span class="token keyword">from</span> manifest of l10n plugins since version 5<span class="token punctuation">.</span>2<span class="token punctuation">.</span>
INFO: SonarQube server 6<span class="token punctuation">.</span>5<span class="token punctuation">.</span>0
INFO: Default locale: <span class="token string">"en_US"</span><span class="token punctuation">,</span> source code encoding: <span class="token string">"UTF-8"</span>
INFO: <span class="token keyword">Process</span> project properties
INFO: Load project repositories
INFO: Load project repositories <span class="token punctuation">(</span>done<span class="token punctuation">)</span> <span class="token punctuation">|</span> time=53ms
INFO: Load quality profiles
INFO: Load quality profiles <span class="token punctuation">(</span>done<span class="token punctuation">)</span> <span class="token punctuation">|</span> time=127ms
INFO: Load active rules
INFO: Load active rules <span class="token punctuation">(</span>done<span class="token punctuation">)</span> <span class="token punctuation">|</span> time=2179ms
INFO: Load metrics repository
INFO: Load metrics repository <span class="token punctuation">(</span>done<span class="token punctuation">)</span> <span class="token punctuation">|</span> time=160ms
WARN: SCM provider autodetection failed<span class="token punctuation">.</span> No SCM provider claims to support this project<span class="token punctuation">.</span> Please use sonar<span class="token punctuation">.</span>scm<span class="token punctuation">.</span>provider to <span class="token keyword">define</span> SCM of your project<span class="token punctuation">.</span>
INFO: Publish mode
INFO: Project key: python-test
INFO: <span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">-</span>  Scan python-test
INFO: Load server rules
INFO: Load server rules <span class="token punctuation">(</span>done<span class="token punctuation">)</span> <span class="token punctuation">|</span> time=118ms
INFO: Language is forced to py
INFO: Base <span class="token function">dir</span>: <span class="token operator">/</span>app/src/sonar-examples-master/projects/languages/python/python-test
INFO: Working <span class="token function">dir</span>: <span class="token operator">/</span>app/src/sonar-examples-master/projects/languages/python/python-test/<span class="token punctuation">.</span>sonar
INFO: Source paths: source
INFO: Source encoding: UTF-8<span class="token punctuation">,</span> default locale: en_US
INFO: Index files
INFO: 1 file indexed
INFO: Quality profile <span class="token keyword">for</span> py: Sonar way
INFO: Sensor PythonXUnitSensor <span class="token namespace">[python]</span>
INFO: Sensor PythonXUnitSensor <span class="token namespace">[python]</span> <span class="token punctuation">(</span>done<span class="token punctuation">)</span> <span class="token punctuation">|</span> time=14ms
INFO: Sensor Python Squid Sensor <span class="token namespace">[python]</span>
INFO: Python unit test coverage
INFO: Python integration test coverage
INFO: Python overall test coverage
INFO: Sensor Python Squid Sensor <span class="token namespace">[python]</span> <span class="token punctuation">(</span>done<span class="token punctuation">)</span> <span class="token punctuation">|</span> time=181ms
INFO: Sensor SonarJavaXmlFileSensor <span class="token namespace">[java]</span>
INFO: Sensor SonarJavaXmlFileSensor <span class="token namespace">[java]</span> <span class="token punctuation">(</span>done<span class="token punctuation">)</span> <span class="token punctuation">|</span> time=0ms
INFO: Sensor Analyzer <span class="token keyword">for</span> <span class="token string">"php.ini"</span> files <span class="token namespace">[php]</span>
INFO: Sensor Analyzer <span class="token keyword">for</span> <span class="token string">"php.ini"</span> files <span class="token namespace">[php]</span> <span class="token punctuation">(</span>done<span class="token punctuation">)</span> <span class="token punctuation">|</span> time=5ms
INFO: Sensor Zero Coverage Sensor
INFO: Sensor Zero Coverage Sensor <span class="token punctuation">(</span>done<span class="token punctuation">)</span> <span class="token punctuation">|</span> time=15ms
INFO: Sensor CPD Block Indexer
INFO: Sensor CPD Block Indexer <span class="token punctuation">(</span>done<span class="token punctuation">)</span> <span class="token punctuation">|</span> time=15ms
INFO: No SCM system was detected<span class="token punctuation">.</span> You can use the <span class="token string">'sonar.scm.provider'</span> property to explicitly specify it<span class="token punctuation">.</span>
INFO: 1 file had no CPD blocks
INFO: Calculating CPD <span class="token keyword">for</span> 0 files
INFO: CPD calculation finished
INFO: Analysis report generated in 90ms<span class="token punctuation">,</span> <span class="token function">dir</span> size=20 KB
INFO: Analysis reports compressed in 11ms<span class="token punctuation">,</span> zip size=6 KB
INFO: Analysis report uploaded in 716ms
INFO: ANALYSIS SUCCESSFUL<span class="token punctuation">,</span> you can browse http:<span class="token operator">/</span><span class="token operator">/</span>localhost:9000/dashboard/index/python-test
INFO: Note that you will be able to access the updated dashboard once the server has processed the submitted analysis report
INFO: More about the report processing at http:<span class="token operator">/</span><span class="token operator">/</span>localhost:9000/api/ce/task?id=AWy9UfSW-QGXbgTpuy0A
INFO: Task total time: 8<span class="token punctuation">.</span>471 s
INFO: <span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span>
INFO: EXECUTION SUCCESS
INFO: <span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span>
INFO: Total time: 12<span class="token punctuation">.</span>703s
INFO: Final Memory: 43M/106M
INFO: <span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>
<p>此时再去sonarqube网站上查看，已经多了2个问题了<br><img src="https://img-blog.csdnimg.cn/85d7238f3b6e412487188a285c2507eb.png" alt="请添加图片描述"><br>然后我们再把source中的python代码修改正确，然后再次测试看看情况</p>
<pre class="line-numbers language-powershell" data-language="powershell"><code class="language-powershell"><span class="token namespace">[root@jenkins python-test]</span><span class="token comment"># vim source/test.py </span>
<span class="token comment">#/usr/bin/env python</span>
print<span class="token punctuation">(</span><span class="token string">"hello world"</span><span class="token punctuation">)</span>

<span class="token namespace">[root@jenkins python-test]</span><span class="token comment"># /app/sonar-scanner/bin/sonar-scanner </span>
INFO: Scanner configuration file: <span class="token operator">/</span>app/sonar-scanner/conf/sonar-scanner<span class="token punctuation">.</span>properties
INFO: Project root configuration file: <span class="token operator">/</span>app/src/sonar-examples-master/projects/languages/python/python-test/sonar-project<span class="token punctuation">.</span>properties
INFO: SonarQube Scanner 2<span class="token punctuation">.</span>6<span class="token punctuation">.</span>1
INFO: Java 1<span class="token punctuation">.</span>8<span class="token punctuation">.</span>0_121 Oracle Corporation <span class="token punctuation">(</span>64-bit<span class="token punctuation">)</span>
INFO: Linux 3<span class="token punctuation">.</span>10<span class="token punctuation">.</span>0-957<span class="token punctuation">.</span>12<span class="token punctuation">.</span>2<span class="token punctuation">.</span>el7<span class="token punctuation">.</span>x86_64 amd64
INFO: User cache: <span class="token operator">/</span>root/<span class="token punctuation">.</span>sonar/cache
INFO: Load global settings
INFO: Load global settings <span class="token punctuation">(</span>done<span class="token punctuation">)</span> <span class="token punctuation">|</span> time=142ms
WARN: Property <span class="token string">'sonar.jdbc.url'</span> is not supported any more<span class="token punctuation">.</span> It will be ignored<span class="token punctuation">.</span> There is no longer any DB connection to the SQ database<span class="token punctuation">.</span>
WARN: Property <span class="token string">'sonar.jdbc.username'</span> is not supported any more<span class="token punctuation">.</span> It will be ignored<span class="token punctuation">.</span> There is no longer any DB connection to the SQ database<span class="token punctuation">.</span>
WARN: Property <span class="token string">'sonar.jdbc.password'</span> is not supported any more<span class="token punctuation">.</span> It will be ignored<span class="token punctuation">.</span> There is no longer any DB connection to the SQ database<span class="token punctuation">.</span>
INFO: User cache: <span class="token operator">/</span>root/<span class="token punctuation">.</span>sonar/cache
INFO: Load plugins index
INFO: Load plugins index <span class="token punctuation">(</span>done<span class="token punctuation">)</span> <span class="token punctuation">|</span> time=8ms
INFO: Plugin <span class="token namespace">[l10nzh]</span> defines <span class="token string">'l10nen'</span> as base plugin<span class="token punctuation">.</span> This metadata can be removed <span class="token keyword">from</span> manifest of l10n plugins since version 5<span class="token punctuation">.</span>2<span class="token punctuation">.</span>
INFO: SonarQube server 6<span class="token punctuation">.</span>5<span class="token punctuation">.</span>0
INFO: Default locale: <span class="token string">"en_US"</span><span class="token punctuation">,</span> source code encoding: <span class="token string">"UTF-8"</span>
INFO: <span class="token keyword">Process</span> project properties
INFO: Load project repositories
INFO: Load project repositories <span class="token punctuation">(</span>done<span class="token punctuation">)</span> <span class="token punctuation">|</span> time=230ms
INFO: Load quality profiles
INFO: Load quality profiles <span class="token punctuation">(</span>done<span class="token punctuation">)</span> <span class="token punctuation">|</span> time=61ms
INFO: Load active rules
INFO: Load active rules <span class="token punctuation">(</span>done<span class="token punctuation">)</span> <span class="token punctuation">|</span> time=862ms
INFO: Load metrics repository
INFO: Load metrics repository <span class="token punctuation">(</span>done<span class="token punctuation">)</span> <span class="token punctuation">|</span> time=73ms
WARN: SCM provider autodetection failed<span class="token punctuation">.</span> No SCM provider claims to support this project<span class="token punctuation">.</span> Please use sonar<span class="token punctuation">.</span>scm<span class="token punctuation">.</span>provider to <span class="token keyword">define</span> SCM of your project<span class="token punctuation">.</span>
INFO: Publish mode
INFO: Project key: python-test
INFO: <span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">-</span>  Scan python-test
INFO: Load server rules
INFO: Load server rules <span class="token punctuation">(</span>done<span class="token punctuation">)</span> <span class="token punctuation">|</span> time=83ms
INFO: Language is forced to py
INFO: Base <span class="token function">dir</span>: <span class="token operator">/</span>app/src/sonar-examples-master/projects/languages/python/python-test
INFO: Working <span class="token function">dir</span>: <span class="token operator">/</span>app/src/sonar-examples-master/projects/languages/python/python-test/<span class="token punctuation">.</span>sonar
INFO: Source paths: source
INFO: Source encoding: UTF-8<span class="token punctuation">,</span> default locale: en_US
INFO: Index files
INFO: 1 file indexed
INFO: Quality profile <span class="token keyword">for</span> py: Sonar way
INFO: Sensor PythonXUnitSensor <span class="token namespace">[python]</span>
INFO: Sensor PythonXUnitSensor <span class="token namespace">[python]</span> <span class="token punctuation">(</span>done<span class="token punctuation">)</span> <span class="token punctuation">|</span> time=41ms
INFO: Sensor Python Squid Sensor <span class="token namespace">[python]</span>
INFO: Python unit test coverage
INFO: Python integration test coverage
INFO: Python overall test coverage
INFO: Sensor Python Squid Sensor <span class="token namespace">[python]</span> <span class="token punctuation">(</span>done<span class="token punctuation">)</span> <span class="token punctuation">|</span> time=569ms
INFO: Sensor SonarJavaXmlFileSensor <span class="token namespace">[java]</span>
INFO: Sensor SonarJavaXmlFileSensor <span class="token namespace">[java]</span> <span class="token punctuation">(</span>done<span class="token punctuation">)</span> <span class="token punctuation">|</span> time=0ms
INFO: Sensor Analyzer <span class="token keyword">for</span> <span class="token string">"php.ini"</span> files <span class="token namespace">[php]</span>
INFO: Sensor Analyzer <span class="token keyword">for</span> <span class="token string">"php.ini"</span> files <span class="token namespace">[php]</span> <span class="token punctuation">(</span>done<span class="token punctuation">)</span> <span class="token punctuation">|</span> time=5ms
INFO: Sensor Zero Coverage Sensor
INFO: Sensor Zero Coverage Sensor <span class="token punctuation">(</span>done<span class="token punctuation">)</span> <span class="token punctuation">|</span> time=17ms
INFO: Sensor CPD Block Indexer
INFO: Sensor CPD Block Indexer <span class="token punctuation">(</span>done<span class="token punctuation">)</span> <span class="token punctuation">|</span> time=25ms
INFO: No SCM system was detected<span class="token punctuation">.</span> You can use the <span class="token string">'sonar.scm.provider'</span> property to explicitly specify it<span class="token punctuation">.</span>
INFO: 1 file had no CPD blocks
INFO: Calculating CPD <span class="token keyword">for</span> 0 files
INFO: CPD calculation finished
INFO: Analysis report generated in 128ms<span class="token punctuation">,</span> <span class="token function">dir</span> size=20 KB
INFO: Analysis reports compressed in 14ms<span class="token punctuation">,</span> zip size=6 KB
INFO: Analysis report uploaded in 54ms
INFO: ANALYSIS SUCCESSFUL<span class="token punctuation">,</span> you can browse http:<span class="token operator">/</span><span class="token operator">/</span>localhost:9000/dashboard/index/python-test
INFO: Note that you will be able to access the updated dashboard once the server has processed the submitted analysis report
INFO: More about the report processing at http:<span class="token operator">/</span><span class="token operator">/</span>localhost:9000/api/ce/task?id=AWy9VWr5-QGXbgTpuy0B
INFO: Task total time: 6<span class="token punctuation">.</span>789 s
INFO: <span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span>
INFO: EXECUTION SUCCESS
INFO: <span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span>
INFO: Total time: 9<span class="token punctuation">.</span>013s
INFO: Final Memory: 43M/106M
INFO: <span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>
<p>再去网址上查看，已经恢复正常<br><img src="https://img-blog.csdnimg.cn/41e69965ca3443939d2e743aed04162a.png" alt="请添加图片描述"><br><img src="https://img-blog.csdnimg.cn/b711ac0ec6a24e4bb9b78e05fefb26cc.png" alt="请添加图片描述"><br>然后如何将代码扫描放到jenkins中，<br>代码扫描2中方式：<br>1，在代码里执行shell命令放进去扫描<br>2，在代码克隆完之后用jenkins触发，帮我们做扫描</p>
<h1 id="三、Jenkins关联到SonarQube"><a href="#三、Jenkins关联到SonarQube" class="headerlink" title="三、Jenkins关联到SonarQube"></a>三、Jenkins关联到SonarQube</h1><p> <strong>1. 安装插件，配置jenkins关联到sonarQube</strong><br>首先安装插件，在jenkins插件安装界面安装Sonar 插件SonarQube Plugin<br><img src="https://img-blog.csdnimg.cn/6a73ecfd5f54412c88f150fae137b91e.png" alt="请添加图片描述"><br>安装成功之后需要到系统配置中配置sonarQube<br><img src="https://img-blog.csdnimg.cn/0259642b765748a3b4be7dd1e6fbc8b2.png" alt="请添加图片描述"><br><img src="https://img-blog.csdnimg.cn/d259acb05ddb43f98ff599dee886e9b8.png" alt="请添加图片描述"><br>填写sonarQube名字，可以随意些，URL需要写sonarqube服务器，我这里jenkins和sonarqube在同一台机器，tonken不用设置<img src="https://img-blog.csdnimg.cn/2fb1826755114ef2966ea8d400fbbc54.png" alt="请添加图片描述"></p>
<p> <strong>2. 让jeknins关联到sonarscanner</strong><br> 添加扫描器<br>系统管理Global Tool Configuration 全局工具配置<br><img src="https://img-blog.csdnimg.cn/d042c179e4f24194ac456fcf82950f6d.png" alt="请添加图片描述"><br>配置sonarQube Scanner 配置<br><img src="https://img-blog.csdnimg.cn/f9957e1046514d9c812809ad08bb79a1.png" alt="请添加图片描述"></p>
<p> <strong>3. 配置扫描</strong><br> 选择自己的项目<br><img src="https://img-blog.csdnimg.cn/68f16357fb634214b094eab148a6957a.png" alt="请添加图片描述"><br>选择配置项目</p>
<p><img src="https://img-blog.csdnimg.cn/95d0b53c8aa74f9995a66f420006218f.png" alt="请添加图片描述"><br>构建execute sonarqube sacnner<br><img src="https://img-blog.csdnimg.cn/e3ed00d586634aec8000361ced1fa3e7.png" alt="请添加图片描述"><br>将配置文件的内容修改成如下格式，然后将Execute SonarQube Scanner 和Excute Shell调换位置，先扫描后执行命令，填写完成然后点击保存。</p>
<pre class="line-numbers language-powershell" data-language="powershell"><code class="language-powershell">sonar<span class="token punctuation">.</span>projectKey=testDemo
sonar<span class="token punctuation">.</span>projectName=testDemo
sonar<span class="token punctuation">.</span>projectVersion=1<span class="token punctuation">.</span>0
sonar<span class="token punctuation">.</span>source=<span class="token punctuation">.</span><span class="token operator">/</span>   
sonar<span class="token punctuation">.</span>language=php
sonar<span class="token punctuation">.</span>sourceEncoding=UTF-8<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>
<p><img src="https://img-blog.csdnimg.cn/ea0f5de92932438a8dcc80def9199198.png" alt="请添加图片描述"></p>
</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">文章作者: </span><span class="post-copyright-info"><a href="http://dycloudnavite.love">J.</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">文章链接: </span><span class="post-copyright-info"><a href="http://dycloudnavite.love/2019/09/23/SonarQube%E4%BB%A3%E7%A0%81%E6%89%AB%E6%8F%8F/">http://dycloudnavite.love/2019/09/23/SonarQube%E4%BB%A3%E7%A0%81%E6%89%AB%E6%8F%8F/</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="http://dycloudnavite.love" target="_blank">J.のblog</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/dujie5416/tags/jenkins/">jenkins</a><a class="post-meta__tags" href="/dujie5416/tags/SonarQube/">SonarQube</a></div><div class="post_share"><div class="addthis_inline_share_toolbox"></div><script src="//s7.addthis.com/js/300/addthis_widget.js#pubid=ra-5d034d84b42927bf" async="async"></script></div></div><div class="post-reward"><div class="reward-button"><i class="fas fa-qrcode"></i> 打赏</div><div class="reward-main"><ul class="reward-all"><li class="reward-item"><a href="/dujie5416/img/wechat.jpg" target="_blank"><img class="post-qr-code-img" src="/dujie5416/img/wechat.jpg" alt="微信"/></a><div class="post-qr-code-desc">微信</div></li><li class="reward-item"><a href="/dujie5416/img/alipay.jpg" target="_blank"><img class="post-qr-code-img" src="/dujie5416/img/alipay.jpg" alt="支付宝"/></a><div class="post-qr-code-desc">支付宝</div></li></ul></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/dujie5416/2019/10/10/centos7%E7%94%9F%E6%88%90%E9%9A%8F%E6%9C%BA%E6%95%B0/"><img class="prev-cover" src="/dujie5416/img/centos.png" onerror="onerror=null;src='/dujie5416/img/404.jpg'" alt="cover of previous post"><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info">生成随机数</div></div></a></div><div class="next-post pull-right"><a href="/dujie5416/2019/06/10/%E6%89%A9%E5%AE%B9%E6%A0%B9%E5%88%86%E5%8C%BA/"><img class="next-cover" src="/dujie5416/img/centos.png" onerror="onerror=null;src='/dujie5416/img/404.jpg'" alt="cover of next post"><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">扩容根分区</div></div></a></div></nav><div class="relatedPosts"><div class="headline"><i class="fas fa-thumbs-up fa-fw"></i><span>相关推荐</span></div><div class="relatedPosts-list"><div><a href="/dujie5416/2022/08/16/Jenkins%E7%94%A8%E6%88%B7%E6%9D%83%E9%99%90%E6%8E%A7%E5%88%B6%E6%8F%92%E4%BB%B6%E2%80%94%E2%80%94Role-based%20Authorization%20Strategy/" title="Jenkins用户权限控制插件——Role-based Authorization Strategy"><img class="cover" src="/dujie5416/img/jenkins.png" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2022-08-16</div><div class="title">Jenkins用户权限控制插件——Role-based Authorization Strategy</div></div></a></div><div><a href="/dujie5416/2020/05/02/pipeline%E5%88%86%E5%B8%83%E5%BC%8F%E6%9E%84%E5%BB%BA%E5%92%8Cpipline%E5%9F%BA%E7%A1%80%E8%AF%AD%E6%B3%95/" title="pipeline分布式构建和pipline基础语法"><img class="cover" src="/dujie5416/img/jenkins.png" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2020-05-02</div><div class="title">pipeline分布式构建和pipline基础语法</div></div></a></div></div></div><hr/><div id="post-comment"><div class="comment-head"><div class="comment-headline"><i class="fas fa-comments fa-fw"></i><span> 评论</span></div></div><div class="comment-wrap"><div><div id="lv-container" data-id="city" data-uid="MTAyMC81Njk5OS8zMzQ2Mw=="></div></div></div></div></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="is-center"><div class="avatar-img"><img src="/dujie5416/img/touxiang.png" onerror="this.onerror=null;this.src='/dujie5416/img/friend_404.gif'" alt="avatar"/></div><div class="author-info__name">J.</div><div class="author-info__description"></div></div><div class="card-info-data site-data is-center"><a href="/dujie5416/archives/"><div class="headline">文章</div><div class="length-num">73</div></a><a href="/dujie5416/tags/"><div class="headline">标签</div><div class="length-num">17</div></a><a href="/dujie5416/categories/"><div class="headline">分类</div><div class="length-num">11</div></a></div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span><span class="toc-percentage"></span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#%E4%B8%80%E3%80%81%E4%BB%A3%E7%A0%81%E8%B4%A8%E9%87%8F%E6%B5%8B%E8%AF%95"><span class="toc-number">1.</span> <span class="toc-text">一、代码质量测试</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E4%BA%8C%E3%80%81%E9%83%A8%E7%BD%B2%E6%89%AB%E6%8F%8F%E5%99%A8-sonar-scanner"><span class="toc-number">2.</span> <span class="toc-text">二、部署扫描器 sonar-scanner</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E4%B8%89%E3%80%81Jenkins%E5%85%B3%E8%81%94%E5%88%B0SonarQube"><span class="toc-number">3.</span> <span class="toc-text">三、Jenkins关联到SonarQube</span></a></li></ol></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item"><a class="thumbnail" href="/dujie5416/2023/07/29/%E6%A0%B9%E6%8D%AErouter%E6%98%BE%E7%A4%BA%E5%B7%A6%E4%BE%A7%E8%8F%9C%E5%8D%95%E6%A0%8F%E9%9A%90%E8%97%8F%E6%9F%90%E4%B8%AA%E8%8F%9C%E5%8D%95%E9%80%89%E9%A1%B9/" title="vue3左侧菜单隐藏某选项"><img src="/dujie5416/img/golang.png" onerror="this.onerror=null;this.src='/dujie5416/img/404.jpg'" alt="vue3左侧菜单隐藏某选项"/></a><div class="content"><a class="title" href="/dujie5416/2023/07/29/%E6%A0%B9%E6%8D%AErouter%E6%98%BE%E7%A4%BA%E5%B7%A6%E4%BE%A7%E8%8F%9C%E5%8D%95%E6%A0%8F%E9%9A%90%E8%97%8F%E6%9F%90%E4%B8%AA%E8%8F%9C%E5%8D%95%E9%80%89%E9%A1%B9/" title="vue3左侧菜单隐藏某选项">vue3左侧菜单隐藏某选项</a><time datetime="2023-07-29T06:32:00.000Z" title="发表于 2023-07-29 14:32:00">2023-07-29</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/dujie5416/2023/07/13/Vue%E7%8A%B6%E6%80%81%E7%AE%A1%E7%90%86/" title="Vue状态管理"><img src="/dujie5416/img/golang.png" onerror="this.onerror=null;this.src='/dujie5416/img/404.jpg'" alt="Vue状态管理"/></a><div class="content"><a class="title" href="/dujie5416/2023/07/13/Vue%E7%8A%B6%E6%80%81%E7%AE%A1%E7%90%86/" title="Vue状态管理">Vue状态管理</a><time datetime="2023-07-13T09:29:00.000Z" title="发表于 2023-07-13 17:29:00">2023-07-13</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/dujie5416/2023/06/27/%E5%9F%BA%E4%BA%8EIOC%E8%A7%A3%E5%86%B3%E5%AF%B9%E8%B1%A1%E4%BE%9D%E8%B5%96%E9%97%AE%E9%A2%98/" title="基于IOC解决对象依赖问题"><img src="/dujie5416/img/golang.png" onerror="this.onerror=null;this.src='/dujie5416/img/404.jpg'" alt="基于IOC解决对象依赖问题"/></a><div class="content"><a class="title" href="/dujie5416/2023/06/27/%E5%9F%BA%E4%BA%8EIOC%E8%A7%A3%E5%86%B3%E5%AF%B9%E8%B1%A1%E4%BE%9D%E8%B5%96%E9%97%AE%E9%A2%98/" title="基于IOC解决对象依赖问题">基于IOC解决对象依赖问题</a><time datetime="2023-06-27T03:32:00.000Z" title="发表于 2023-06-27 11:32:00">2023-06-27</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/dujie5416/2023/06/23/Gin%E6%A1%86%E6%9E%B6/" title="Gin框架"><img src="/dujie5416/img/golang.png" onerror="this.onerror=null;this.src='/dujie5416/img/404.jpg'" alt="Gin框架"/></a><div class="content"><a class="title" href="/dujie5416/2023/06/23/Gin%E6%A1%86%E6%9E%B6/" title="Gin框架">Gin框架</a><time datetime="2023-06-23T06:32:00.000Z" title="发表于 2023-06-23 14:32:00">2023-06-23</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/dujie5416/2023/06/04/ServeMux%E3%80%81httprouter/" title="ServeMux、httprouter"><img src="/dujie5416/img/golang.png" onerror="this.onerror=null;this.src='/dujie5416/img/404.jpg'" alt="ServeMux、httprouter"/></a><div class="content"><a class="title" href="/dujie5416/2023/06/04/ServeMux%E3%80%81httprouter/" title="ServeMux、httprouter">ServeMux、httprouter</a><time datetime="2023-06-04T03:32:00.000Z" title="发表于 2023-06-04 11:32:00">2023-06-04</time></div></div></div></div></div></div></main><footer id="footer" style="background-image: url('/dujie5416/img/longzhu.png')"><div id="footer-wrap"><div class="copyright">&copy;2019 - 2024  <i id="heartbeat" class="fa fas fa-heartbeat"></i> J.</div><div class="framework-info"><span>框架 </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>主题 </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a><a href="http://beian.miit.gov.cn/"  style="color:#f72b07" target="_blank">京ICP备2022023567号</a></div></div><link rel="stylesheet" href="https://fastly.jsdelivr.net/gh/HCLonely/images@master/others/heartbeat.min.css"></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="translateLink" type="button" title="简繁转换">繁</button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><a id="to_comment" href="#post-comment" title="直达评论"><i class="fas fa-comments"></i></a><button id="go-up" type="button" title="回到顶部"><i class="fas fa-arrow-up"></i></button></div></div><div id="algolia-search"><div class="search-dialog"><nav class="search-nav"><span class="search-dialog-title">搜索</span><button class="search-close-button"><i class="fas fa-times"></i></button></nav><div class="search-wrap"><div id="algolia-search-input"></div><hr/><div id="algolia-search-results"><div id="algolia-hits"></div><div id="algolia-pagination"></div><div id="algolia-info"><div class="algolia-stats"></div><div class="algolia-poweredBy"></div></div></div></div></div><div id="search-mask"></div></div><div id="rightMenu"><div class="rightMenu-group rightMenu-small"><div class="rightMenu-item" id="menu-backward"><i class="fa-solid fa-arrow-left"></i></div><div class="rightMenu-item" id="menu-forward"><i class="fa-solid fa-arrow-right"></i></div><div class="rightMenu-item" id="menu-refresh"><i class="fa-solid fa-arrow-rotate-right"></i></div><div class="rightMenu-item" id="menu-home"><i class="fa-solid fa-house"></i></div></div><div class="rightMenu-group rightMenu-line rightMenuOther"><a class="rightMenu-item menu-link" href="/archives/"><i class="fa-solid fa-archive"></i><span>文章归档</span></a><a class="rightMenu-item menu-link" href="/categories/"><i class="fa-solid fa-folder-open"></i><span>文章分类</span></a><a class="rightMenu-item menu-link" href="/tags/"><i class="fa-solid fa-tags"></i><span>文章标签</span></a></div><div class="rightMenu-group rightMenu-line rightMenuNormal"><a class="rightMenu-item menu-link" id="menu-radompage" href="/random/index.html"><i class="fa-solid fa-shoe-prints"></i><span>随便逛逛</span></a><div class="rightMenu-item" id="menu-translate"><i class="fa-solid fa-earth-asia"></i><span>繁简切换</span></div><div class="rightMenu-item" id="menu-darkmode"><i class="fa-solid fa-moon"></i><span>切换模式</span></div></div></div><div id="rightmenu-mask"></div><div><script src="/dujie5416/js/utils.js"></script><script src="/dujie5416/js/main.js"></script><script src="/dujie5416/js/tw_cn.js"></script><script src="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.umd.min.js"></script><script src="https://cdn.jsdelivr.net/npm/algoliasearch/dist/algoliasearch-lite.umd.min.js"></script><script src="https://cdn.jsdelivr.net/npm/instantsearch.js/dist/instantsearch.production.min.js"></script><script src="/dujie5416/js/search/algolia.js"></script><script>var preloader = {
  endLoading: () => {
    document.body.style.overflow = 'auto';
    document.getElementById('loading-box').classList.add("loaded")
  },
  initLoading: () => {
    document.body.style.overflow = '';
    document.getElementById('loading-box').classList.remove("loaded")

  }
}
window.addEventListener('load',preloader.endLoading())</script><div class="js-pjax"><script>function loadLivere () {
  if (typeof LivereTower === 'object') {
    window.LivereTower.init()
  }
  else {
    (function(d, s) {
        var j, e = d.getElementsByTagName(s)[0];
        if (typeof LivereTower === 'function') { return; }
        j = d.createElement(s);
        j.src = 'https://cdn-city.livere.com/js/embed.dist.js';
        j.async = true;
        e.parentNode.insertBefore(j, e);
    })(document, 'script');
  }
}

if ('Livere' === 'Livere' || !false) {
  if (false) btf.loadComment(document.getElementById('lv-container'), loadLivere)
  else loadLivere()
}
else {
  function loadOtherComment () {
    loadLivere()
  }
}</script></div><script defer src="https://npm.elemecdn.com/jquery@latest/dist/jquery.min.js"></script><script data-pjax defer src="https://npm.elemecdn.com/tzy-blog/lib/js/theme/chocolate.js"></script><canvas id="universe"></canvas><script defer src="/js/universe.js"></script><script defer data-pjax src="/js/rightMenu.js"></script><div class="aplayer no-destroy" data-id="7427714271" data-server="netease" data-type="playlist" data-fixed="true" data-mini="true" data-listFolded="false" data-order="random" data-lrctype="1" data-preload="none" data-autoplay="true" muted></div><script id="click-show-text" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/dist/click-show-text.min.js" data-mobile="false" data-text="I,LOVE,YOU" data-fontsize="15px" data-random="false" async="async"></script><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/aplayer/dist/APlayer.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/aplayer/dist/APlayer.min.js"></script><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/metingjs/dist/Meting.min.js"></script><script src="https://cdn.jsdelivr.net/npm/pjax/pjax.min.js"></script><script>let pjaxSelectors = ["meta[property=\"og:image\"]","meta[property=\"og:title\"]","meta[property=\"og:url\"]","head > title","#config-diff","#body-wrap","#rightside-config-hide","#rightside-config-show",".js-pjax"]

var pjax = new Pjax({
  elements: 'a:not([target="_blank"])',
  selectors: pjaxSelectors,
  cacheBust: false,
  analytics: false,
  scrollRestoration: false
})

document.addEventListener('pjax:send', function () {

  // removeEventListener scroll 
  window.tocScrollFn && window.removeEventListener('scroll', window.tocScrollFn)
  window.scrollCollect && window.removeEventListener('scroll', scrollCollect)

  typeof preloader === 'object' && preloader.initLoading()
  document.getElementById('rightside').style.cssText = "opacity: ''; transform: ''"
  
  if (window.aplayers) {
    for (let i = 0; i < window.aplayers.length; i++) {
      if (!window.aplayers[i].options.fixed) {
        window.aplayers[i].destroy()
      }
    }
  }

  typeof typed === 'object' && typed.destroy()

  //reset readmode
  const $bodyClassList = document.body.classList
  $bodyClassList.contains('read-mode') && $bodyClassList.remove('read-mode')

  typeof disqusjs === 'object' && disqusjs.destroy()
})

document.addEventListener('pjax:complete', function () {
  window.refreshFn()

  document.querySelectorAll('script[data-pjax]').forEach(item => {
    const newScript = document.createElement('script')
    const content = item.text || item.textContent || item.innerHTML || ""
    Array.from(item.attributes).forEach(attr => newScript.setAttribute(attr.name, attr.value))
    newScript.appendChild(document.createTextNode(content))
    item.parentNode.replaceChild(newScript, item)
  })

  GLOBAL_CONFIG.islazyload && window.lazyLoadInstance.update()

  typeof chatBtnFn === 'function' && chatBtnFn()
  typeof panguInit === 'function' && panguInit()

  // google analytics
  typeof gtag === 'function' && gtag('config', '', {'page_path': window.location.pathname});

  // baidu analytics
  typeof _hmt === 'object' && _hmt.push(['_trackPageview',window.location.pathname]);

  typeof loadMeting === 'function' && document.getElementsByClassName('aplayer').length && loadMeting()

  // prismjs
  typeof Prism === 'object' && Prism.highlightAll()

  typeof preloader === 'object' && preloader.endLoading()
})

document.addEventListener('pjax:error', (e) => {
  if (e.request.status === 404) {
    pjax.loadUrl('/404.html')
  }
})</script><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div><!-- hexo injector body_end start --><script data-pjax>
  function butterfly_clock_anzhiyu_injector_config(){
    var parent_div_git = document.getElementsByClassName('sticky_layout')[0];
    var item_html = '<div class="card-widget card-clock"><div class="card-glass"><div class="card-background"><div class="card-content"><div id="hexo_electric_clock"><img class="entered loading" id="card-clock-loading" src="https://cdn.cbd.int/hexo-butterfly-clock-anzhiyu/lib/loading.gif" style="height: 120px; width: 100%;" data-ll-status="loading"/></div></div></div></div></div>';
    console.log('已挂载butterfly_clock_anzhiyu')
    if(parent_div_git) {
      parent_div_git.insertAdjacentHTML("afterbegin",item_html)
    }
  }
  var elist = 'null'.split(',');
  var cpage = location.pathname;
  var epage = 'all';
  var qweather_key = '56289903f0d448dfbe8262dba0175f70';
  var gaud_map_key = '01603f2b2d08d0e947bb101e9d9b148b';
  var baidu_ak_key = 'undefined';
  var flag = 0;
  var clock_rectangle = '112.982279,28.19409';
  var clock_default_rectangle_enable = 'false';

  for (var i=0;i<elist.length;i++){
    if (cpage.includes(elist[i])){
      flag++;
    }
  }

  if ((epage ==='all')&&(flag == 0)){
    butterfly_clock_anzhiyu_injector_config();
  }
  else if (epage === cpage){
    butterfly_clock_anzhiyu_injector_config();
  }
  </script><script src="https://widget.qweather.net/simple/static/js/he-simple-common.js?v=2.0"></script><script data-pjax src="https://cdn.cbd.int/hexo-butterfly-clock-anzhiyu/lib/clock.min.js"></script><!-- hexo injector body_end end --><script src="/dujie5416/live2dw/lib/L2Dwidget.min.js?094cbace49a39548bed64abff5988b05"></script><script>L2Dwidget.init({"tagMode":false,"debug":false,"model":{"jsonPath":"/dujie5416/live2dw/assets/tororo.model.json"},"display":{"position":"right","width":150,"height":350,"hOffset":20,"vOffset":-20},"mobile":{"show":false},"log":false,"pluginJsPath":"lib/","pluginModelPath":"assets/","pluginRootPath":"live2dw/"});</script><script async>window.onload=function(){var a=document.createElement('script'),b=document.getElementsByTagName('script')[0];a.type='text/javascript',a.async=!0,a.src='/sw-register.js?v='+Date.now(),b.parentNode.insertBefore(a,b)};</script></body></html>